﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ecdl.demo.model {

    public interface ITaskEvaluation {
        ITask Task { get; }
        int Points { get; }
        string Cause { get; set; }
        bool IsCorrect { get; }
    }

    public class TaskEvaluation : ITaskEvaluation {

        public TaskEvaluation(ITask task, int points)
            : this(task, points, string.Empty) {
        }

        public TaskEvaluation(ITask task, int points, string cause) {
            Task = task;
            Points = Math.Min(points, task.MaxPoints);
            Cause = cause;
        }

        public ITask Task { get; private set; }

        public int Points { get; private set; }

        public string Cause { get; set; }

        public bool IsCorrect {
            get { return Points > 0; }
        }

        public static ITaskEvaluation CreateFromExpressionState(ITask task, expression.ExpressionState state) {
            int points = 0;
            if (state.IsOk){
                points = task.MaxPoints;
            }

            return new TaskEvaluation(task, points, state.GetCause(true));
        }
    }
}
